package com.tzbank.back.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tzbank.back.dao.ProductEvalutionMapper;
import com.tzbank.back.service.ProductEvaluationService;
import com.tzbank.entity.backstage.ProductEvaluation;
import com.tzbank.utils.CodeUtil;
import com.tzbank.utils.ResultUtil;

import net.sf.json.JSONObject;
/**
 * 产品评价配置
 * @author 蔡宇钿
 *2018年5月29日
 *更新 蔡宇钿 2018.6.1
 */
@Service(value="productEvaluationService")
public class ProductEvaluationServiceImpl implements ProductEvaluationService {
	
	@Autowired
	private ProductEvalutionMapper productEvalutionMapper;
	
	@Transactional
	@Override
	public Map<String, Object> deleteByproductautoId(ProductEvaluation cptcInfoJson) throws Exception{
		// 通过逻辑方式实现删除
		cptcInfoJson.setStatus("0");
		cptcInfoJson.setUpdateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		this.productEvalutionMapper.deleteByproductautoId(cptcInfoJson);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}

	@Override
	public Map<String, Object> getlistByapplication(String application) throws Exception{
		// 按照application查询
		ProductEvaluation ProductEvalution = this.productEvalutionMapper.getlistByapplication(application);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), ProductEvalution);
	}

	@Override
	public Map<String, Object> getlistProduct() throws Exception{
		// 查询全部
		List<ProductEvaluation> ProductEvalution = this.productEvalutionMapper.getlistProduct();
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), ProductEvalution);
	}

	@Transactional
	@Override
	public Map<String, Object> addProduct(ProductEvaluation cptcInfoJson) throws Exception{
		// 增加配置
		cptcInfoJson.setCreateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		cptcInfoJson.setUpdateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		productEvalutionMapper.addProduct(cptcInfoJson);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}

	@Transactional
	@Override
	public Map<String, Object> modifyByproductautoId(ProductEvaluation cptcInfoJson) throws Exception{
		//更新配置
		cptcInfoJson.setUpdateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		this.productEvalutionMapper.modifyByproductautoId(cptcInfoJson);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}

}
